# -*- coding: utf-8 -*-
import sys
import logging
from lxml import etree
from xadmin.model import *
from xadmin.lib.base import *
from xadmin.lib.trazability import Trazability

class PRPRODTrazability(Trazability):
    def get(self):
        pass

    def getTrazaByProject(self, project):
        try:
            project = Session.query(Project).get(project)
            c.product_requirements = Session.query(ProductRequirement).filter_by(project_id=project.id).all()
            c.products = Session.query(Product).filter_by(project_id=project.id).all()
            #Busca los id de
            #dict de la forma {nameprod: [id_pr_realcionados]}
            dictlist = {}
            for prod in c.products:
                dictlist[prod.name] = [assoc.pr_id for assoc in prod.products_requirements_assoc]
            #print dictlist
            c.product_id_list = dictlist
            return render('/trazability/prprod.mako')
        except:
            print "ERROR: ", sys.exc_info()[0]
            return None